package farmer.gui;

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.geom.RoundRectangle2D;

import core.gui.Button;
import farmer.game.Data;
import farmer.game.FarmerBoyGame;
import farmer.game.InGameMenuState;

public class InGameMenuButton extends Button{
	
	private InGameMenuState state;
	private int type;
	
	public InGameMenuButton(String name, int type, InGameMenuState state){
		super(name);
		this.state = state;
		this.type = type;
		this.boundingRect = new RoundRectangle2D.Float(0, 0, 10, 10, 10, 10);
		this.setSize(250, 50);
	}
	
	@Override
	public void isClicked(){
		if(type == InGameMenuGUI.resume){
			state.getGame().enterState(FarmerBoyGame.MainGame);
		}else if(type == InGameMenuGUI.restart){
			Data.status = Data.failed;
			state.getGame().enterState(FarmerBoyGame.MainGame);
		}else if(type == InGameMenuGUI.quit){
			Data.status = Data.failed;
			state.getGame().enterState(FarmerBoyGame.MainMenu);
		}
	}
	
	private BasicStroke stroke = new BasicStroke(1);
	private Font font = new Font("Button", Font.BOLD, 17);
	@Override
	protected void drawButton(Graphics2D g){
		g.setFont(font);
		int x = (int) boundingRect.getCenterX();
		int y = (int) boundingRect.getCenterY();
		int w = g.getFontMetrics().charsWidth(name.toCharArray(), 0, name.length());
		int h = g.getFontMetrics().getHeight();
		g.setColor(Color.black);
		g.setStroke(stroke);
		g.drawString(name, x-w/2, y+h/4);
		g.drawString("_", x-w/2, y+h/4);
	}

}
